package com.cheng.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import com.cheng.frame.CreateCodeFrame;
import com.cheng.frame.InputInfoFrame;
import com.cheng.util.DataUtil;


public class CheckInfoListener extends MouseAdapter implements ActionListener{
	private JTextField tName;
	private JTextField tSex;
	private JTextField tPlace;
	private JTextField tNation;
	private JTextField tBirth;
	private JTextField tSchool;
	private JTextField tSnum;
	private JTextField tSyear;
	private JTextField tScardID;
	private JTextArea tRemark;
	private JComboBox tQuestion;
	private JTextField tAnswer;
	private JButton bNext;
	
	public CheckInfoListener(JTextField tName, JTextField tSex,JTextField tPlace,
			JTextField tNation,JTextField tBirth,JTextField tSchool,JTextField tSnum,
			JTextField tSyear,JTextField tScardID,JTextArea tRemark,JComboBox tQuestion,
			JTextField tAnswer,JButton bNext){
		this.tName = tName;
		this.tSex = tSex;
		this.tPlace = tPlace;
		this.tNation = tNation;
		this.tBirth = tBirth;
		this.tSchool = tSchool;
		this.tSnum = tSnum;
		this.tSyear = tSyear;
		this.tScardID = tScardID;
		this.tRemark = tRemark;
		this.tQuestion = tQuestion;
		this.tAnswer = tAnswer;
		this.bNext = bNext;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == bNext){
			if(tName.getText().trim().equals("")||tSex.getText().trim().equals("")||
					tPlace.getText().trim().equals("")||tNation.getText().trim().equals("")||
					tBirth.getText().trim().equals("")||tSchool.getText().trim().equals("")||
					tSnum.getText().trim().equals("")||tSyear.getText().trim().equals("")||
					tScardID.getText().trim().equals("")||tQuestion.getSelectedItem().toString().trim().equals("")||tAnswer.getText().trim().equals("")){
				JOptionPane.showMessageDialog(null, "必填信息不能为空！", "提示",
						JOptionPane.ERROR_MESSAGE);
			}else{
				DataUtil.instance().clearAll();
				
				StringBuffer msSb = new StringBuffer();
				msSb.append(tName.getText().trim());
				msSb.append("/");
				msSb.append(tSex.getText().trim());
				msSb.append("/");
				msSb.append(tPlace.getText().trim());
				msSb.append("/");
				msSb.append(tNation.getText().trim());
				msSb.append("/");
				msSb.append(tBirth.getText().trim());
				msSb.append("/");
				msSb.append(tSchool.getText().trim());
				msSb.append("/");
				msSb.append(tSnum.getText().trim());
				msSb.append("/");
				msSb.append(tSyear.getText().trim());
				msSb.append("/");
				msSb.append(tScardID.getText().trim());
				msSb.append("/");
				msSb.append(tRemark.getText().trim().equals("")?" ":tRemark.getText().trim());
				DataUtil.instance().setMs(msSb.toString());
				
				StringBuffer psSb = new StringBuffer();
				psSb.append(tQuestion.getSelectedItem().toString().trim());
				psSb.append("/");
				psSb.append(tAnswer.getText().trim());
				DataUtil.instance().setPs(psSb.toString());
				
				InputInfoFrame.instance().setVisible(false);
				CreateCodeFrame.instance().getInfoShowPanel().showInfo();
				CreateCodeFrame.instance().getJPanel2().setVisible(false);
				CreateCodeFrame.instance().getJPanel1().setVisible(true);
				CreateCodeFrame.instance().setVisible(true);
				CreateCodeFrame.instance().requestFocus();
				CreateCodeFrame.instance().show();
			}
		}
	}

}
